<?php
/**
 * 定时任务
 * User: admin
 * Date: 2017/8/17
 * Time: 20:04
 */

namespace Api\Controller;


use Think\Controller;

class BatchController extends  Controller
{

    /**
     * 自动退红包
     */
    function returnRedbag(){
        $map['deadline']=array('lt',NOW_TIME);
        $map['status'] =0;
        $list = M('red_task','cmf_')->where($map)->select();

        foreach ($list as &$li){
            $tasks = M('par_task','cmf_')->where('task_id='.$li['id'])->select();
            foreach ($tasks as &$ta){
                //更新为已退款
                $map2['status']=3;
                $map2['uptime']=time();
                $flag= M('par_task','cmf_')->where('task_id='.$ta['task_id'])->save($map2);

             //   M('users','cmf_')->where('id='.$ta['uid'])->setInc('coin',$ta['paymoney']);
                /*//退还记录
                $record['coin'] =$ta['paymoney'];
                $record['type'] = 3;
                $record['uid'] = $ta['uid'];
                $record['task_id']=$ta['task_id'];
                $record['uptime'] = time();
                $r= M('record','cmf_')->add($record);*/

            }
            //更新为拼福失败
            $where['status'] = 2;
            $where['uptime'] = time();
            $re =M('red_task','cmf_')->where('id='.$li['id'])->save($where);

        }
    }

}